/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Data;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author NGOCLINH-PC
 */
public class Prize {

    int PrizeID;
    int PrizeTypeID;
    int EventID;
    int MemberID;
    String PrizeName;
    int Status;

    public Prize() {
    }

    public Prize(int PrizeID, int PrizeTypeID, int EventID, int MemberID, String PrizeName, int Status) {
        this.PrizeID = PrizeID;
        this.PrizeTypeID = PrizeTypeID;
        this.EventID = EventID;
        this.MemberID = MemberID;
        this.PrizeName = PrizeName;
        this.Status = Status;
    }

    public int getPrizeID() {
        return PrizeID;
    }

    public void setPrizeID(int PrizeID) {
        this.PrizeID = PrizeID;
    }

    public int getPrizeTypeID() {
        return PrizeTypeID;
    }

    public void setPrizeTypeID(int PrizeTypeID) {
        this.PrizeTypeID = PrizeTypeID;
    }

    public int getEventID() {
        return EventID;
    }

    public void setEventID(int EventID) {
        this.EventID = EventID;
    }

    public int getMemberID() {
        return MemberID;
    }

    public void setMemberID(int MemberID) {
        this.MemberID = MemberID;
    }

    public String getPrizeName() {
        return PrizeName;
    }

    public void setPrizeName(String PrizeName) {
        this.PrizeName = PrizeName;
    }

    public int getStatus() {
        return Status;
    }

    public void setStatus(int Status) {
        this.Status = Status;
    }

    public static void Pdelete(int CateID) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("DELETE FROM Prize WHERE PrizeID='" + CateID + "'");
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "DELETE Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void Pupdate(int id, String type, String event, String member, String prizename, int Status) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("update Prize SET PrizeTypeID=?,EventID=?,MemberID=?,PrizeName=?,Status=? WHERE PrizeID=?");
            st.setString(1, type);
            st.setString(2, event);
            st.setString(3, member);
            st.setString(4, prizename);
            st.setInt(5, Status);
            st.setInt(6, id);
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "Update Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void Pinsert( int type, int event, int member, String prizename, int Status) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("insert into Prize values(?,?,?,?,?)");
            st.setInt(1, type);
            st.setInt(2, event);
            st.setInt(3, member);
            st.setString(4, prizename);
            st.setInt(5, Status);
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "insert Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public ArrayList<Prize> Pselect() {
        try {
            ArrayList<Prize> listCate = new ArrayList<Prize>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM Prize");
            while (rs.next()) {
                Prize cate = new Prize(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getString(5), rs.getInt(6));
                listCate.add(cate);// 
            }
            return listCate;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public ArrayList<Prize> PselectByID(int id) {
        try {
            ArrayList<Prize> listCate = new ArrayList<Prize>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM Prize where PrizeID=" + id);
            while (rs.next()) {
                Prize cate = new Prize(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getString(5), rs.getInt(6));
                listCate.add(cate);// 
            }
            return listCate;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
